package cn.tedu.toa.management.sys.service.impl;

import cn.tedu.toa.management.sys.entity.FInfocompany;
import cn.tedu.toa.management.sys.mapper.FInfocompanyMapper;
import cn.tedu.toa.management.sys.service.FInfocompanyService;
import cn.tedu.toa.management.sys.vo.AboutUsVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 公司信息表 服务实现类
 * </p>
 *
 * @author huaqian
 * @since 2021-10-02
 */
@Service
public class FInfocompanyServiceImpl extends ServiceImpl<FInfocompanyMapper, FInfocompany> implements FInfocompanyService {

    @Autowired
    private FInfocompanyMapper infocompanyMapper;

    private AboutUsVo aboutUsVo = new AboutUsVo();



    @Override
    public AboutUsVo aboutUs() {
        List<FInfocompany> fInfocompanies = infocompanyMapper.selectList(null);
        for (FInfocompany infocompany:fInfocompanies
             ) {
            switch (infocompany.getFKey()){
                case "telephone":
                    aboutUsVo.setTelephone(infocompany.getFValue());
                    break;
                case "phone":
                    aboutUsVo.setPhone(infocompany.getFValue());
                    break;
                case "name":
                    aboutUsVo.setName(infocompany.getFValue());
                    break;
                case "email":
                    aboutUsVo.setEmail(infocompany.getFValue());
                    break;
                case "aboutUs":
                    aboutUsVo.setAboutUs(infocompany.getFValue());
                    break;
                case "address":
                    aboutUsVo.setAddress(infocompany.getFValue());
                    break;
            }
        }
        return aboutUsVo;
    }

    @Override
    @RequiresPermissions("sys:cominfo:save")
    public void updateComInfo(AboutUsVo aboutUsVo) {
        List<FInfocompany> fInfocompanies = infocompanyMapper.selectList(null);
        for(FInfocompany infocompany :fInfocompanies){
            switch (infocompany.getFKey()){
                case "telephone":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getTelephone().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("telephone",aboutUsVo.getTelephone());
                    }
                    break;
                case "phone":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getPhone().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("phone",aboutUsVo.getPhone());
                    }
                    break;
                case "name":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getName().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("name",aboutUsVo.getName());
                    }
                    break;
                case "email":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getEmail().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("email",aboutUsVo.getEmail());
                    }
                    break;
                case "aboutUs":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getAboutUs().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("aboutUs",aboutUsVo.getAboutUs());
                    }
                    break;
                case "address":
                    //比较一下是否相同,不同就更新
                    if(!aboutUsVo.getAddress().equals(infocompany.getFValue())){
                        infocompanyMapper.updateByName("address",aboutUsVo.getAddress());
                    }
                    break;
            }



        }


    }


}
